/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/customerRepresentativeService.ts" />
/// <reference path="../src/tms.ts" />

describe('getCustomerRepresentativeList',()=>{
    var injector:ng.auto.IInjectorService;
    var service:ICustomerRepresentativeService;

    beforeEach(()=>{
        injector=angular.injector(['ng','tms']);
        service=injector.get<ICustomerRepresentativeService>('customerRepresentativeService');
    });

    //常规无条件获取
    it('get customerRepresentative list normal',(done)=>{
        service.getList(null,null,null,0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取企业公司编号包含 1 的客户代表列表
    it('get customerRepresentative list by enterpriseid \'1 \'',(done)=>{
        service.getList('1',null,null,0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('1|||0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取姓名包含 结算蕊 的客户代表列表
    it('get customerRepresentative list by realName \'结算蕊\'',(done)=>{
        service.getList(null,'结算蕊',null,0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|结算蕊||0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取职位包含 结算员 的客户代表列表
    it('get customerRepresentative list by job \'结算员\'',(done)=>{
        service.getList(null,null,'结算员',0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||结算员|0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取 企业公司编号包含 2， 姓名包含 结算蕊 ,职位包含 结算员 的客户代表列表
    it('get customerRepresentative list by enterpriseid \'2\' and realName \'结算蕊\' and job \'结算员\'',(done)=>{
        service.getList('2','结算蕊','结算员',0,10).then((res)=>{
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('2|结算蕊|结算员|0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });


    //获取客户代表详细
    it('get detail',(done)=>{
        service.getDetail('2').then((res)=>{
            expect(res.data.enterpriseCompanyId).toBe("2");
            expect(res.data.realName).toBe("detail");
            expect(res.data.job).toBe("客服");
            expect(res.data.phoneNumber).toBe("15854565852");
            expect(res.data.remarks).toBe("备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加客户代表
    it('add customerRepresentative',(done)=>{
        service.add('2','测试蕊','测试','18352868222','备注').then((res)=>{
            expect(res.data.extData).toBe("2|测试蕊|测试|18352868222|备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //编辑客户代表
    it('edit customerRepresentative',(done)=>{
        service.edit('1','1','测试蕊2','测试2','18352868225','备注2').then((res)=>{
            expect(res.data.extData).toBe("1|1|测试蕊2|测试2|18352868225|备注2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除客户代表
    it('delete customerRepresentative',(done)=>{
        service.delete('2').then((res)=>{
            expect(res.data.extData).toBe("2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

});